
/*视频*/
$(function(){
    $(window).scroll(function () {
        var _video_box =$(".video-introduce");
        var scrollHeight = _video_box.height();
        if ($(window).scrollTop() >= scrollHeight){
            _video_box.find(".enjoy-video").addClass("video-move");
            $(".video-move").animate({'bottom':'20px'},1000);
        }else{
            $(".video-move").css('bottom','-400px');
            $(".video-move").removeAttr("style");
            _video_box.find(".enjoy-video").removeClass("video-move");
        }
    });
//  //分享给朋友，鼠标hover效果
//  $(".video-box  .video-action .video-share a").hover(function () {
//      var index = $(this).index();
//      $(this).css('background-position', index * -32 + 'px ' + '-542px');
//  }, function () {
//      var index = $(this).index();
//      $(this).css('background-position', index * -32 + 'px ' + '-520px');
//  });
    $.fn.move_article_fn = function(){
        var _self = $(this);
        var M = function(width,num){
                return _self.animate({'margin-left' :-width*num +'px'},1000);
        }
        _self.find(" ul:first-child").addClass("active");
        var moveWidth = _self.find("ul").width();
        var num = _self.find("ul").length;
        $("._prev").click(function () {
                var i = _self.find("ul.active").index();
                if( i == 0){
                        return;
                }
                var move = i-1;
                _self.find(" ul").eq(i).removeClass("active").prev().addClass("active");
                return M(moveWidth,move);
        });
        $("._next").click(function () {
                var i = _self.find(" ul.active").index();
                if( (i + 1) == num){
                        return;
                }
                var move = i+1;
                _self.find(" ul").eq(i).removeClass("active").next().addClass("active");
                return M(moveWidth,move);
        });
    }
    $(".video-details .hot-video .hot-lists .list").move_article_fn();
    var is_invalid = true;
    $(".video-like-btn").click(function(){
        if(!_is_login()){return;};
        if(!is_invalid){return;}
        var _self=$(this),_like=_self.attr("data-value"),_vid=$("#_T_video_info").attr("data-vid"),_type=_self.attr("data-type");
        if(_like == 1) return;
        _like = _like + 1;_self.attr("data-value",_like);is_invalid = false;
        doRequest("/ajax/video_like_num_add",{video_id:_vid,status:_like,type:_type},true,function(data){
            _self.text(data.num);
            if(data.type == "like"){
                _self.addClass("like")
            }else{
                _self.addClass("hate")
            }
        },function(data){
            is_invalid = true;
        });
    });

    //视频回复
    $("body").delegate(".V-comment-btn","click",function(){
        if(!_is_login()){return;}
        var _self=$(this),_vid=$("#_T_video_info").attr("data-vid"),_content=$("#comment-content").val(),_tag_obj=$(".reply-tags ul li[class='on']"),
            _novilad=_self.attr("data-disable-val"),_commentid=_self.attr("data-comment-id"),_comment_uid=_self.attr("data-comment-uuid"),_card=0;
        if($.trim(_content) == ""){layer.msg("请输入回复的内容哦",{icon:0,offset:300,time:1000});return;}
        if(typeof(_tag_obj[0])!="undefined"){_card=_tag_obj.attr("data-tag");}
        _self.attr("disabled","disabled").addClass("nvilad").val(_novilad);
        doRequest("/ajax/comment_video_add",{content:_content,vid:_vid,comment_id:_commentid,comment_uid:_comment_uid,card:_card},true,function(data){
            window.location.href=data.comment_url;
        },function(data){
            _self.removeAttr("disabled").removeClass("nvilad").val("发表回复");
            layer.msg(data.errorMsg,{icon:0,offset:300,time:1000});
        });
    });
    
    $(".icon-video-collect").click(function(){
        if(!_is_login()){return;};
        var _self=$(this),_favor=_self.attr("data-value"),_vid=$("#_T_video_info").attr("data-vid");
        _favor=1-_favor;$(".icon-video-collect").attr("data-value",_favor);
        if(_favor==1){
            $(".icon-video-collect").addClass("collected");
        }else{
            $(".icon-video-collect").removeClass("collected");
        }
        doRequest("/ajax/video_favor_act",{collectId:_vid,is_favor:_favor},true,function(data){},function(data){layer.msg(data.errorMsg,{icon:0,offset:300,time:2000});});
    }).mouseover(function(){
        var _self=$(this),_favor=_self.attr("data-value");
        if(_favor == 1){
            $(this).css('background-position', _self.index() * -32 + 'px ' + '-542px');
        }
    }).mouseout(function(){
        var _self=$(this),_favor=_self.attr("data-value");
        if(_favor == 1){
            $(this).css('background-position', _self.index() * -32 + 'px ' + '-542px');
        }
    });
    $(".goto-comment_video-box").on("click",function(){
        $(".V-comment-btn").attr("data-comment-id","").attr("data-comment-uuid","");
        var t;return t=$("#comment-content").offset().top,$("html, body").stop(true,true).animate({scrollTop:(t-80)},800),$("#comment-content").attr("placeholder","写下你的评论...").focus();
    });
});
//显示视频详情页面评论
function showVideoComment(pageIndex){
    pageIndex = typeof(pageIndex) == "undefined" ? 0 : pageIndex;
    var containerId = "show-comment-pagination",_vid=$("#_T_video_info").attr("data-vid"),_comment_id=$("#_T_video_info").attr("data-comment");
    $(".comment-box-list").html("<span class='load-tag'></span>");
    setTimeout(function(){
        doRequest("/ajax/get_video_comments_json",{vid:_vid,comment_id:_comment_id,pageIndex:pageIndex,goto:is_goto_comment,stamptime:Math.random()},true,function(resp){
            var totalCount = resp.data.totalCount,targetId=resp.data.targetId,isGoto=resp.data.isGoto,totalPage=resp.data.totalPage;
            is_goto_comment = resp.data.goto;
            var str = "";$(".comment-total-page").text(totalPage == 0?1:totalPage);$(".comment-total-count").text(totalCount);$(".total_num").text("("+totalCount+")");
            if(totalCount == 0){
                str += "<div class='tip-null' style='height:165px;'></div>";
            }else{
                var htmlData = resp.data.htmlData;
                str += AnalyticEmotion(htmlData);
            }
            $(".comment-box-list").html(str);
            if(isGoto){
                 setTimeout(function(){
                    if(isGoto){
                        var t;return t=$("body").find("#comment-"+targetId).offset().top,$("html, body").stop(true).animate({scrollTop:(t-10)},800);
                    } 
                 },100);
            }
            createComplexPaginationModel({containerId:containerId,perNum:30,currIndex:resp.data.pageIndex,totalCount:totalCount},showVideoComment,"class");
        },function(data){});
    },400);
}
function delete_video_comment_act(opt){
    if(!_is_login()){return;};
    if(!confirm("确定要删除此评论吗")){return;}
    doRequest("/ajax/cancel_video_comment_act",{comment_id:opt.comment_id,stamptime:Math.random()},true,function(resp){
        layer.msg("成功删除",{icon:0,offset:300,time:1000});
        showVideoComment();
    },function(data){
        layer.msg(data.errorMsg,{icon:0,offset:300,time:2000});
    });
}
function showVideoRead(){
    var _vid = $("#_T_video_info").attr("data-vid");
    doGetRequest("/ajax/video_read_num_add",{vid:_vid,stamptime:Math.random()},false,function(data){$(".read_num_show").html(data.readNum);},function(data){});
}
function award_video(){
    var a = $(".reward-popup"),
        c = a.find(".close"),
        la = $(".reward-content ul li a");
    la.on("click",function(){
        var _s = $(this);
        if(_s.children("b").hasClass("icon-support-noyue")){
            layer.msg("余额不足哦！",{icon:0,time:1000,offset:300});return false;
        }
        _s.toggleClass("icon-support-choice");
        _s.siblings().removeClass("icon-support-choice")
    })
    c.on("click",function(){
        a.hide();
    });
    a.fadeIn(200);
}
function action_award_video_order_pay_do(form){
    if(!_is_login()){return false;};
    var awardNum=$(form).children().find("#awardNum"),awardPayObj=$(form).children().find(".pay .icon-support-choice"),awardPayVal=awardPayObj.attr("data-pay"),awardSay=$(form).children().find("#awardSay"),
            awardSub=$(form).children().find("input[type=submit]"),awardLoad=$(form).children().find(".load-show"),_key=$(form).children().find("#awardKey"),_videoId=$(form).children().find("#videoId"),
            _action=$(form).children().find("#awardAction"),_pay=$(form).children().find("#awardPay");
    if(awardNum.val() ==0 || awardNum.val() == ""){layer.msg("打赏溜珠的个数需≥1",{icon:0,offset:300,time:2000});return false;}
    if(typeof(awardPayObj[0]) == "undefined"){layer.msg("请选择支付方式",{icon:0,offset:300,time:2000});return false;}
    if(awardPayVal != "alipay" && awardPayVal != "yue" && awardPayVal != "weixin"){layer.msg("支付方式选择有误",{icon:0,offset:300,time:2000});return false;}
    _pay.val(awardPayVal);
    if(awardPayVal == "yue"){
        awardLoad.addClass("award-loading").html("打赏中");awardSub.addClass("nvilad");
        doRequest($(form).attr("action"),{awardKey:_key.val(),action:_action.val(),awardNum:awardNum.val(),awardSay:awardSay.val(),videoId:_videoId.val(),awardPay:awardPayVal,time:Math.random()},true,function(data){
            $(".reward-popup").hide();$(".popup").hide();
            layer.msg(data.errorMsg,{icon:6,offset:300,time:1000},function(){window.location.reload();});
        },function(data){
            layer.msg(data.errorMsg,{icon:0,offset:300,time:2000});
            awardLoad.removeClass("award-loading").html("");awardSub.removeClass("nvilad");
        });
        return false;
    }
    $(".reward-popup").hide();$(".popup").hide();
    return true;
}